<?php

//WP Cart Add Products Menu
function wp_dk_estore_add_product_menu_tpl()
{

	echo '<div class="wrap">';
	echo "<h2>Add/Edit Products</h2>";
	echo '<div id="poststuff"><div id="post-body">';

	$eStore_products_per_page = get_option('eStore_products_per_page');
	if (empty($eStore_products_per_page)) 
	{
        echo '<div id="message" class="updated fade"><p>';
        echo 'It appears that you have never saved your settings after installing the plugin! Please visit the settings page of this plugin and save it.';
        echo '</p></div>';  			
	}
	
	global $wpdb;
	global $products_table_name;
	global $cat_prod_rel_table_name;
	global $cat_table_name;
	$product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME;

	//If product is being edited, grab current product info
	if ($_GET['editproduct']!='')
	{
		$theid = $_GET['editproduct'];
		$editingproduct = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$theid'", OBJECT);
	}

	if ($_POST['Submit'])
	{
        if(empty($_POST['productname']))
        {
            echo '<div id="message" class="updated fade"><p>'.__('Product name cannot be empty!', 'wp_eStore').'</p></div>';
        }
        else
        {
		$chars_to_replace = array("\r\n", "\n", "\r");//Used to replaced hidden chars in various fields
		            	
        $curr_symbol = get_option('cart_currency_symbol');
		$post_editedproduct = $wpdb->escape($_POST['editedproduct']);
		$post_productid = $wpdb->escape($_POST['productid']);
		
		//$tmp_name = htmlentities(stripslashes($_POST['productname']) , ENT_COMPAT, "UTF-8");
		$tmp_name = strip_tags(stripslashes($_POST['productname']));
        $post_productname = $wpdb->escape($tmp_name);
		$post_productprice = $wpdb->escape($_POST['productprice']);		
		if(empty($_POST['a3'])){//filter the price field value if this is not a subscription product
			$post_productprice = str_replace($curr_symbol,"",$post_productprice);
		}
		
		$post_producturl = trim($wpdb->escape($_POST['producturl']));
		$post_product_downloadable = $wpdb->escape($_POST['productdownloadable']);
		$post_product_shipping = $wpdb->escape($_POST['shippingcost']);
		$post_product_available_copies = $wpdb->escape($_POST['availablecopies']);
		$post_product_button_image_url = trim($wpdb->escape($_POST['buttonimageurl']));
		$post_product_return_url = trim($wpdb->escape($_POST['returnurl']));
		$paypal_email = $wpdb->escape($_POST['paypal_email']);
		$post_product_sales_count = $wpdb->escape($_POST['salescount']);	
		//$post_product_description = $wpdb->escape($_POST['productdesc']);
		$tmpdescription = htmlentities(stripslashes($_POST['productdesc']) , ENT_COMPAT, "UTF-8");

		$post_product_description = $wpdb->escape($tmpdescription);
		$post_product_thumbnail = trim($wpdb->escape($_POST['productthumb']));

        $post_product_variation1 = $wpdb->escape(stripslashes($_POST['variation1']));
        $post_product_variation2 = $wpdb->escape(stripslashes($_POST['variation2']));
        $post_product_variation3 = $wpdb->escape(stripslashes($_POST['variation3']));
        $post_product_variation3 = str_replace($chars_to_replace,"",$post_product_variation3);//replace any hidden newlines
		$variation4 = $wpdb->escape(stripslashes($_POST['variation4']));

		$post_product_commission = trim($wpdb->escape($_POST['productcommission']));
		
		if ($post_product_downloadable=='on'){
			$post_product_downloadable = 'yes';
		}
		else{
			$post_product_downloadable = 'no';
		}
		// Subscription related fields
		$a1 = $wpdb->escape($_POST['a1']);
		$p1 = $wpdb->escape($_POST['p1']);
		$t1 = $wpdb->escape($_POST['t1']);
		$a3 = $wpdb->escape($_POST['a3']);
		$p3 = $wpdb->escape($_POST['p3']);
		$t3 = $wpdb->escape($_POST['t3']);
		$sra = $wpdb->escape($_POST['sra']);
		$srt = $wpdb->escape($_POST['srt']);
		$ref_text = $wpdb->escape($_POST['ref_text']);
		if ($sra=='on'){
            $sra='1';
        }
        else{
            $sra='0';
        }
		$custom_input = $wpdb->escape($_POST['custom_input']);
		if ($custom_input=='on'){
            $custom_input='1';
        }
        else{
            $custom_input='0';
        }
        $custom_input_label = $wpdb->escape($_POST['custom_input_label']);
        $aweber_list = $wpdb->escape(trim(stripslashes($_POST['aweber_list'])));
        $currency_code = $wpdb->escape($_POST['currency_code']);
        $target_thumb_url = trim($wpdb->escape($_POST['target_thumb_url']));
        $target_button_url = trim($wpdb->escape($_POST['target_button_url']));
        $weight = $wpdb->escape($_POST['itemweight']);
        $product_url = trim($wpdb->escape($_POST['product_url']));
		$tmp_item_spec_instruction = stripslashes($_POST['item_spec_instruction']);
        $post_item_spec_instruction = $wpdb->escape($tmp_item_spec_instruction);      
        
        $ppv_content = $wpdb->escape($_POST['ppv_content']);
		if ($ppv_content=='on'){
            $ppv_content='1';
        }
        else{
            $ppv_content='0';
        }              
        $use_pdf_stamper = $wpdb->escape($_POST['use_pdf_stamper']);
		if ($use_pdf_stamper=='on'){
            $use_pdf_stamper='1';
        }
        else{
            $use_pdf_stamper='0';
        }   
           
        $create_license = $wpdb->escape($_POST['create_license']);
		if ($create_license=='on'){
            $create_license='1';
        }
        else{
            $create_license='0';
        }      
        $post_tax = $wpdb->escape($_POST['tax']);    
        $post_author_id = trim($wpdb->escape($_POST['author_id']));   
        $show_qty = $wpdb->escape($_POST['show_qty']);
		if ($show_qty=='on'){
            $show_qty='1';
        }
        else{
            $show_qty='0';
        }    
        $tier2_commission = $wpdb->escape($_POST['tier2_commission']);   
        $custom_price_option = $wpdb->escape($_POST['custom_price_option']);
		if ($custom_price_option=='on'){
            $custom_price_option='1';
        }
        else{
            $custom_price_option='0';
        }
        $post_additional_images = $wpdb->escape($_POST['additional_images']);  
        $post_additional_images = str_replace($chars_to_replace,"",$post_additional_images);//replace any hidden newlines 
         
        $post_oldprice = $wpdb->escape($_POST['old_price']);
        $post_rev_share_commission = $wpdb->escape($_POST['rev_share_commission']);
        $post_rev_share_commission = str_replace($curr_symbol,"",$post_rev_share_commission);
        $post_rev_share_commission = str_replace("%","",$post_rev_share_commission);        
        $post_per_customer_qty_limit = $wpdb->escape($_POST['per_customer_qty_limit']);
                             
		//----- Some default input values ----------
        if ($post_product_sales_count=='') $post_product_sales_count=0;        
        if ($p1=='') $p1=0;        
        if ($p3=='' || $p3<1) $p3=1;        
        if ($srt=='') $srt=0;
        		
        //Validate the form inputs
        $form_fields_validated = true;
        $validation_error_message = "";
        if(!eStore_is_valid_url_if_not_empty($post_product_thumbnail))
        {
        	$validation_error_message .= "<br /><strong>The URL specified in the \"Thumbnail Image URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
        	$validation_error_message .= "<br />".$post_product_thumbnail."<br />";
        	$form_fields_validated = false;
        }
        if(!eStore_is_valid_url_if_not_empty($target_thumb_url))
        {
        	$validation_error_message .= "<br /><strong>The URL specified in the \"Thumbnail Target URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
        	$validation_error_message .= "<br />".$target_thumb_url."<br />";
        	$form_fields_validated = false;
        }  
        if(!eStore_is_valid_url_if_not_empty($product_url))
        {
        	$validation_error_message .= "<br /><strong>The URL specified in the \"Product Page URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
        	$validation_error_message .= "<br />".$product_url."<br />";
        	$form_fields_validated = false;
        } 
        if(!eStore_is_valid_url_if_not_empty($post_product_button_image_url))
        {
        	$validation_error_message .= "<br /><strong>The URL specified in the \"Button Image URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
        	$validation_error_message .= "<br />".$post_product_button_image_url."<br />";
        	$form_fields_validated = false;
        }    
        if(!eStore_is_valid_url_if_not_empty($target_button_url))
        {
        	$validation_error_message .= "<br /><strong>The URL specified in the \"Button Redirect Target URL\" field does not seem to be a valid URL! Please check this value again:</strong>";
        	$validation_error_message .= "<br />".$target_button_url."<br />";
        	$form_fields_validated = false;
        }                            
        if(!$form_fields_validated)
        {
			//Get the updated product again
			$_GET['editproduct'] = $post_editedproduct;
			$editingproduct = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$post_editedproduct'", OBJECT);      
			        	
        	echo '<div id="message" class="error fade"><p>';
        	echo $validation_error_message;
        	echo '</p></div>';  	
        }  
         
        //Insert or Update the database          		
		if ($post_editedproduct=='')//Insert the new product
		{
			$updatedb = "INSERT INTO $products_table_name (name, price, product_download_url, downloadable, shipping_cost, available_copies, button_image_url, return_url, sales_count,description,thumbnail_url,variation1,variation2,variation3,commission,a1,p1,t1,a3,p3,t3,sra,srt,ref_text,paypal_email,custom_input,custom_input_label,variation4,aweber_list,currency_code,target_thumb_url,target_button_url,weight,product_url,item_spec_instruction,ppv_content,use_pdf_stamper,create_license,tax,author_id,show_qty,tier2_commission,custom_price_option,additional_images,old_price,rev_share_commission,per_customer_qty_limit) VALUES ('$post_productname', '$post_productprice','$post_producturl','$post_product_downloadable','$post_product_shipping','$post_product_available_copies','$post_product_button_image_url','$post_product_return_url','$post_product_sales_count','$post_product_description','$post_product_thumbnail','$post_product_variation1','$post_product_variation2','$post_product_variation3','$post_product_commission','$a1','$p1','$t1','$a3','$p3','$t3','$sra','$srt','$ref_text','$paypal_email','$custom_input','$custom_input_label','$variation4','$aweber_list','$currency_code','$target_thumb_url','$target_button_url','$weight','$product_url','$post_item_spec_instruction','$ppv_content','$use_pdf_stamper','$create_license','$post_tax','$post_author_id','$show_qty','$tier2_commission','$custom_price_option','$post_additional_images','$post_oldprice','$post_rev_share_commission','$post_per_customer_qty_limit')";
			$results = $wpdb->query($updatedb);
	
			$wp_eStore_product_ret = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = LAST_INSERT_ID()", OBJECT);
			$cur_product_id = $wp_eStore_product_ret->id;		
			
			//record user id
				update_option( 'dk_eshop_user_product_record' . $cur_product_id , dk_eshop_get_e_member_id());
			
			$user_products = get_option('dk_eshop_user_products_' . dk_eshop_get_e_member_id());
			if(empty($user_products))
				$user_products = array();
			
			if(!in_array($cur_product_id,$user_products))
				$user_products[] = $cur_product_id;
			
			update_option( 'dk_eshop_user_products_' . dk_eshop_get_e_member_id() , $user_products);
			
			
			//Add the new category relationship
			$categories = $_POST['category'];
			if(!empty($categories))
			{
				while (list ($key,$val) = @each ($categories)) { 
					$updatedb = "INSERT INTO $cat_prod_rel_table_name (cat_id, prod_id) VALUES ('$val', '$cur_product_id')";
					$results = $wpdb->query($updatedb);	
				}	
			}	
			//Add product meta data			
			$available_key_codes = $wpdb->escape($_POST['available_key_codes']);			
			if(!empty($available_key_codes)){
				$updatedb = "INSERT INTO $product_meta_table_name (prod_id, meta_key, meta_value) VALUES ('$cur_product_id', 'available_key_codes','$available_key_codes')";
				$results = $wpdb->query($updatedb);
			}
			
			//Get the handle to the inserted product
			$_GET['editproduct'] = $wp_eStore_product_ret->id;
			$editingproduct = $wp_eStore_product_ret;
			echo '<div id="message" class="updated fade"><p>Product &quot;'.$post_productname.'&quot; created.</p></div>';
		}
		else//Update existing product
		{
			$updatedb = "UPDATE $products_table_name SET name = '$post_productname', price = '$post_productprice', product_download_url = '$post_producturl', downloadable = '$post_product_downloadable', shipping_cost = '$post_product_shipping', available_copies = '$post_product_available_copies', button_image_url='$post_product_button_image_url', return_url = '$post_product_return_url', sales_count = '$post_product_sales_count', description = '$post_product_description', thumbnail_url = '$post_product_thumbnail', variation1='$post_product_variation1', variation2='$post_product_variation2',variation3='$post_product_variation3',commission='$post_product_commission',a1='$a1',p1='$p1',t1='$t1',a3='$a3',p3='$p3',t3='$t3',sra='$sra',srt='$srt',ref_text='$ref_text',paypal_email='$paypal_email',custom_input='$custom_input',custom_input_label='$custom_input_label',variation4='$variation4',aweber_list='$aweber_list',currency_code='$currency_code',target_thumb_url='$target_thumb_url',target_button_url='$target_button_url',weight='$weight',product_url='$product_url',item_spec_instruction='$post_item_spec_instruction',ppv_content='$ppv_content',use_pdf_stamper='$use_pdf_stamper',create_license='$create_license',tax='$post_tax',author_id='$post_author_id',show_qty='$show_qty',tier2_commission='$tier2_commission',custom_price_option='$custom_price_option',additional_images='$post_additional_images',old_price='$post_oldprice',rev_share_commission='$post_rev_share_commission',per_customer_qty_limit='$post_per_customer_qty_limit' WHERE id='$post_editedproduct'";
			$results = $wpdb->query($updatedb);
			update_option( 'dk_eshop_user_product_record' . $post_editedproduct , dk_eshop_get_e_member_id());
			
			//Delete the existing category relationship
			$updatedb = "DELETE FROM $cat_prod_rel_table_name WHERE prod_id='$post_editedproduct'";
			$results = $wpdb->query($updatedb);	
			
			//Add the new relationship
			$categories = $_POST['category'];
			if(!empty($categories))
			{
				while (list ($key,$val) = @each ($categories)) { 
					$updatedb = "INSERT INTO $cat_prod_rel_table_name (cat_id, prod_id) VALUES ('$val', '$post_editedproduct')";
					$results = $wpdb->query($updatedb);	
				}	
			}	
			
			//Update product meta data			
			$available_key_codes = $wpdb->escape($_POST['available_key_codes']);		
			//check if a serial key meta value for this product exists
			$editingproductmeta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$post_editedproduct' AND meta_key='available_key_codes'", OBJECT);
			if($editingproductmeta){//update existing meta record
				$meta_key_name = "available_key_codes";			
				$updatedb_meta = "UPDATE $product_meta_table_name SET meta_value='$available_key_codes' WHERE prod_id='$post_editedproduct' AND meta_key='$meta_key_name'";
			}else{//Add new meta record
				$updatedb_meta = "INSERT INTO $product_meta_table_name (prod_id, meta_key, meta_value) VALUES ('$post_editedproduct', 'available_key_codes','$available_key_codes')";
			}
			$results = $wpdb->query($updatedb_meta);				
	
			//Get the handle to the updated product
			$_GET['editproduct'] = $post_editedproduct;
			$editingproduct = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$post_editedproduct'", OBJECT);
			echo '<div id="message" class="updated fade"><p>'.__('Product', 'wp_eStore').' &quot;'.$post_productname.'&quot; '.__('updated.', 'wp_eStore').'</p></div>';
		}
      }
	}
	// Copy Product Details
	if ($_POST['copy_product'])
	{
        $post_orig_product_id = $wpdb->escape($_POST['orig_product_id']);
	    $editingproduct = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$post_orig_product_id'", OBJECT);
	    echo '<div id="message" class="updated fade"><p>'.__('Details from Product ID', 'wp_eStore').' &quot;'.$post_orig_product_id.'&quot; '.__('has been copied. Make your changes and save the new product.', 'wp_eStore').'</p></div>';
	}
	// Delete Product
	if ($_POST['deleteproduct'])
	{
		$post_editedproduct = $wpdb->escape($_POST['editedproduct']);
		echo '<div id="message" class="updated fade"><p>'.__('Do you really want to delete this Product? This action cannot be undone.', 'wp_eStore').' <a href="admin.php?page=dk_eStore_addedit&deleteproduct='.$post_editedproduct.'">'.__('Yes', 'wp_eStore').'</a> &nbsp; <a href="admin.php?page=dk_eStore_addedit&editproduct='.$post_editedproduct.'">'.__('No!', 'wp_eStore').'</a></p></div>';
	}
	
	if ($_GET['deleteproduct']!='')
	{
		$theproduct=$_GET['deleteproduct'];
		$updatedb = "DELETE FROM $products_table_name WHERE id='$theproduct'";
		$results = $wpdb->query($updatedb);

		$updatedb = "DELETE FROM $cat_prod_rel_table_name WHERE prod_id='$theproduct'";
		$results = $wpdb->query($updatedb);		

		$del_meta_db_val = "DELETE FROM $product_meta_table_name WHERE prod_id='$theproduct' AND meta_key='available_key_codes'";
		$results = $wpdb->query($del_meta_db_val);	
		
		dk_eshop_delete_product_belong_user($theproduct);
		echo '<div id="message" class="updated fade"><p>'.__('Product deleted.', 'wp_eStore').'</p></div>';
	}
    eStore_admin_css();
    echo eStore_admin_js_scripts();
?>
<div class="eStore_grey_box">
You can add a new product or edit an existing product from this interface. When creating a new product you can choose to copy the details from an existing product too (see the option below). This option is helpful when creating multiple products with similar details.

</div>	
	<div class="postbox">
	<div class="inside">
<form method="post" action="admin.php?page=dk_eStore_addedit">

<table class="form-table">

<?php if ($_GET['editproduct']!='') 
{ 
	echo '<input name="editedproduct" type="hidden" value="'.$_GET['editproduct'].'" />'; 
	echo '<tr valign="top"><th scope="row">Product ID </th>';
	echo '<td><strong>'.$_GET['editproduct'].'</strong> (This value is for internal use and cannot be changed)</td>';
	echo '</tr>';
} 
?>

<tr valign="top">
<th scope="row">Product Name</th>
<td><input name="productname" type="text" id="productname" value="<?php echo htmlspecialchars($editingproduct->name); ?>" size="40" />
<br /><p class="description">Name of the Product</p></td>
</tr>

<tr valign="top">
<th scope="row">Product Price</th>
<td><input name="productprice" type="text" id="productprice" value="<?php echo $editingproduct->price; ?>" size="20" />
<br/><p class="description">Enter Price to two decimal places. Examples: 10.00 or 6.70 or 1999.95 etc (<strong><i>Do not put currency symbol in the price</i></strong>). See the Subscription payment section below if you are configuring a subscribe button</p></td>
</tr>
</table>

<div class=eStore_blue_box>
<i><strong>Optional Product Details</strong></i> (If any of the following options is not needed for your product you can leave the field empty)
</div>

<div class="msg_head">Additional Product Details (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Product Description</th>
<td><textarea name="productdesc" cols="83" rows="3"><?php echo $editingproduct->description; ?></textarea>
<br/><p class="description">This description is used when displaying products using the fancy display option.</p></td>
</tr>

<tr valign="top">
<th scope="row">Thumbnail Image URL</th>
<td><input name="productthumb" type="text" id="productthumb" value="<?php if ($editingproduct->thumbnail_url!='') { echo $editingproduct->thumbnail_url; } else { echo ''; } ?>" size="100" />
<input type="button" id="productthumb_button" name="productthumb_button" class="button rbutton" value="Upload File" />
<?php wp_eStore_show_file_upload_more_info(); ?>
<p class="description">This thumbnail image is used when displaying products using the fancy display option.</p></td>
</tr>


<tr valign="top">
<th scope="row">Product Category</th>
<td>
<?php
	$wp_eStore_cat_db = $wpdb->get_results("SELECT * FROM $cat_table_name ORDER BY cat_name ASC", OBJECT);
	if ($wp_eStore_cat_db)
	{
		$existing_categories = array();
		if($_GET['editproduct']!='')
		{
            $theid = $_GET['editproduct'];            
		    $editingproduct_cat_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name WHERE prod_id = '$theid'", OBJECT);
		    if ($editingproduct_cat_db)
		    {		    	
		    	foreach ($editingproduct_cat_db as $existing_product_cat)
		    	{
		    		array_push($existing_categories,$existing_product_cat->cat_id);
		    	}
		    }   
		}		
		else if(isset($_POST['copy_product']))
		{
		    $theid = $_POST['orig_product_id'];            
		    $editingproduct_cat_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name WHERE prod_id = '$theid'", OBJECT);
		    if ($editingproduct_cat_db)
		    {		    	
		    	foreach ($editingproduct_cat_db as $existing_product_cat)
		    	{
		    		array_push($existing_categories,$existing_product_cat->cat_id);
		    	}
		    }			
		}
		
		foreach ($wp_eStore_cat_db as $cat_item)
		{
			$checked = "";
			if(in_array($cat_item->cat_id,$existing_categories)){
				$checked = "checked='checked'";
			}			
			echo "<input type='checkbox' name='category[]' value='".$cat_item->cat_id."' ".$checked."/> ".$cat_item->cat_name."<br />";						
		}
	}
	else
	{
		echo 'No Categories Found! <a href="admin.php?page=wp_eStore_categories"><strong>Add a Category</strong></a>';
	}
?>
</td>
</tr>

<tr valign="top">
<th scope="row">Display Quantity Field</th>
<td><input type="checkbox" name="show_qty" <?php if ($editingproduct->show_qty=='1'){echo 'checked="checked"';} ?> />
<br /><p class="description">When checked, it will display a text box next to the Add to Cart button so the customers can enter a quantity amount for the item.</p></td>
</tr>


</table>
</div>

<div class="msg_head">Digital Content Details (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Digital Product URL</th>
<td>
<input id="producturl_button" class="button rbutton" type="button" value="Upload File" />
<span class="eStore_more_info_anchor"> [+] more info<br /></span>
<div class="eStore_more_info_body" style="color:#666666;">
<p>Uploading a file and using it as the digital content of this product is a 3 step process:</p>
<ol>
<li><i>Click the above upload button</i></li> 
<li><i>Choose the file to upload which will upload that file to your media library</i></li> 
<li><i>Finally, click the <strong>Insert into Post</strong> button, this will populate the uploaded file's URL in the following field.</i></li> 
</ol>
</div>
<br />
<input name="producturl" type="text" id="producturl" value="<?php if ($editingproduct->product_download_url!='') { echo $editingproduct->product_download_url; } else { echo ''; } ?>" size="120" />
<p class="description">The URL of the digital product that you are selling (this content will be given to your customer via an encrypted link), example: <code>http://www.example.com/downloads/ebook/superman.zip</code></p> 
<div class="eStore_more_info_anchor">&nbsp;[+] more info</div>
<div class="eStore_more_info_body">
<li style="margin-left:15px;margin-top:10px;color:#666666;"><i>If you haven't uploaded the file to your server yet then you can do so using the <a href="media-new.php" target="_blank">WordPress's Media Uploader</a> or an FTP software. Simply copy the "File URL" after you upload the file and paste it in the above field.</i></li> 
<li style="margin-left:15px;color:#666666;"><i>If you are making a bundled product then enter the product IDs separated by comma (example: 3,8,18). If the product has multiple files then enter the file URLs separated by comma.</i></li> 
<li style="margin-left:15px;color:#666666;"><i>If you want to integrate with Amazon S3 then read <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=1101" target="_blank">this instruction</a> first.</i></li>
<li style="margin-left:15px;color:#666666;"><i>Please note that the file can be kept on any accessible location on the web (<a href="http://www.tipsandtricks-hq.com/forum/topic/download-directory-protection" target="_blank">more explanation here</a>). The buyer will receive an encrypted link which will let them download this product.</i></li>
</div>
</td></tr>

<tr valign="top">
<th scope="row">Downloadable</th>
<td><input type="checkbox" name="productdownloadable" <?php if ($editingproduct->downloadable!='no'){echo 'checked="checked"';} ?> /> 
<p class="description">If checked the digital content will be offered as an anonymous download (the customer won\'t know where it is coming from). If Unchecked the buyer will be redirected to the above URL when they click on the encrypted link (useful for video on demand system)</p></td>
</tr>


</table>
</div>


<div class="msg_head">Shipping & Tax (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Item Shipping Cost</th>
<td><input name="shippingcost" type="text" id="shippingcost" value="<?php echo $editingproduct->shipping_cost; ?>" size="3" />
<br/><p class="description">Enter the Shipping Cost for this item (eg. 5.00). Leave blank if shipping cost does not apply.</p></td>
</tr>
<tr valign="top">
<th scope="row">Item Weight</th>
<td><input name="itemweight" type="text" id="itemweight" value="<?php echo $editingproduct->weight; ?>" size="3" />
<br/><p class="description">Enter the Weight of the item in lbs. This is only used if you are using <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=50" target="_blank">PayPal profile based shipping</a.</p></td>
</tr>
<tr valign="top">
<th scope="row">Item Specific Tax</th>
<td><input name="tax" type="text" id="tax" value="<?php echo $editingproduct->tax; ?>" size="3" />%
<br/><p class="description">If you want to charge a different tax for this item than the one specified in the settings menu then enter the tax rate for this item here.</p></td>
</tr>
</table>
</div>

<div class="msg_head">Inventory Control (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Available Copies</th>
<td><input name="availablecopies" type="text" id="availablecopies" value="<?php echo $editingproduct->available_copies; ?>" size="10" />
<br/><p class="description">Enter the numer of available copies (example: 50). Leave blank if unlimited. This is useful when you only want to sell only 50 copies of a product for example</p></td>
</tr>

<tr valign="top">
<th scope="row">Sales Count</th>
<td><input name="salescount" type="text" id="salescount" value="<?php echo $editingproduct->sales_count; ?>" size="10" />
<br/><p class="description">This is the total sales count. This number gets incremented by the quantity sold when you make a sale</p></td>
</tr>

<tr valign="top">
<th scope="row">Quantity Limit Per Customer</th>
<td><input name="per_customer_qty_limit" type="text" id="per_customer_qty_limit" value="<?php echo $editingproduct->per_customer_qty_limit; ?>" size="10" />
<br/><p class="description">If you want to limit the number of quantity a customer can purchase (example: 1) then enter that number here, otherwise leave this field empty.</p></td>
</tr>
</table>
</div>


<div class="msg_head">Product Specific Instructions for Buyer (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Instructions for Buyer</th>
<td><textarea name="item_spec_instruction" cols="83" rows="3"><?php echo $editingproduct->item_spec_instruction; ?></textarea>
<br/><p class="description">This option is useful when you need to give your customer some specific instruction that applies only to this product (e.g. a secret password for the PDF file). This instruction will be added to the buyer\'s email body when this product is purchased. Use the {product_specific_instructions} tag in the "Buyers Email Body" field in the settings menu to dynamically place this information in the email body.</p></td>
</tr>
</table>
</div>

<div class="msg_head">PayPal Email and Further Options (Click to Expand)</div>
<div class="msg_body">
<table class="form-table">
<tr valign="top">
<th scope="row">Return URL</th>
<td><input name="returnurl" type="text" id="returnurl" value="<?php if ($editingproduct->return_url!='') { echo $editingproduct->return_url; } else { echo ''; } ?>" size="50" />
<br/><p class="description">Can be used to redirect customers to a different URL for this item after a successful payment</p></td>
</tr>
<tr valign="top">
<th scope="row">PayPal Email</th>
<td><input name="paypal_email" type="text" id="paypal_email" value="<?php if ($editingproduct->paypal_email!='') { echo $editingproduct->paypal_email; } else { echo ''; } ?>" size="50" />
<br/><p class="description">Enter your PayPal email to receive payments</p></td>
</tr>
<tr valign="top">
<th scope="row">Currency Code</th>
<td><input name="currency_code" type="text" id="currency_code" value="<?php if ($editingproduct->currency_code!='') { echo $editingproduct->currency_code; } else { echo ''; } ?>" size="6" />
<br/><p class="description">This is useful when you want to sell a specific product in a different currency than the one specified in the settings menu. (e.g. EUR, GBP, AUD, USD) </p></td>
</tr>
</table>
</div>


<p class="submit"><input type="submit" name="Submit" value="Save Product" /> &nbsp; <?php if ($_GET['editproduct']!='') { ?><input type="submit" name="deleteproduct" value="Delete Product" /><?php } ?></p>

</form>
</div></div>

<div class="postbox">
<h3><label for="title">Copy Product Details from an Existing Product</label></h3>
<div class="inside">

To copy the details from an existing product simply enter the ID of the product whose details you wish to copy and hit the "Copy Product Details" button
<br /><br />
<form method="post" action="admin.php?page=dk_eStore_addedit">
Product ID:
<input name="orig_product_id" type="text" id="orig_product_id" value="" size="5" />
<input type="submit" name="copy_product" value="Copy Product Details" />
</form>
</div>
</div>
<?php

	echo 'Want to bulk upload product details from CSV file? <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=775" target="_blank">Click Here to Learn More</a><br /><br />';
	echo '<a href="admin.php?page=dk_eshop/dk_eshop.php" class="button rbutton">Manage Products</a><br /><br />';

	echo '</div>';
}

?>